<?php

require 'facebook.php';
require 'config.inc.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => $fbconfig['app_id'],
  'secret' => $fbconfig['secret_key'],
  'cookie' => true,
));

$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
  try {
    $me = $facebook->getUser();
  } catch (FacebookApiException $e) {
    echo "Somethings wrong";
  }
}

$con = mysql_connect("localhost", "vatsav", "2T*vzcd");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db("vatsav", $con);
if (!$db_selected) {
	die ('Cant use db : ' . mysql_error());
}

$linkid= $_POST["linkid"];
$uid = $_POST["uid"];

//need to use table joins
$query = "select * from links where linkid=$linkid and uid=$uid";
$result = mysql_query($query);	
// Check result
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "<br/>";
   echo $message;
}



$row = mysql_fetch_row($result);

$link_url = $row[1];
$ts = $row[2];
$groupid = $row[4];
$commentid = $row[5];

$link_desc = $row[6];
$link_title = $row[7];
$link_pic= $row[8];
if(is_null($link_pic)){
	$link_pic = "images/no_image.gif";
}

//uid of the user who shared the link
//no. of likes
$query = "select distinct count(*) from likes where uid=".$uid." and linkid=".$linkid;
$result= mysql_query($query);	
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "<br/>";
   echo $message;
}

$row = mysql_fetch_row($result);
$num_likes=$row[0];

$query = "select group_name from groups where uid=$uid and groupid=$groupid";
$result= mysql_query($query);	
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "<br/>";
   echo $message;
}

$row = mysql_fetch_row($result);
$group_name=$row[0];
$group_name_len = strlen($group_name);	
$group_name_new = substr($group_name,0,30);
if($group_name_len != strlen($group_name))
{
	$group_name_new .= "...";
}


$user = $facebook->api('/'.$uid);
$name = $user["name"];

?>

<div class="post">
	<div class="post_left">
		<img class="img_src" alt="No Image Available" src="<?php echo $link_pic; ?>" />
		<div class="like">
			<a class="likes_url" href="javascript:like(<?php echo $uid.','.$linkid; ?>)"> 
				<img src="images/thumbs-up-small.png" alt="like"/>  <?php echo $num_likes; ?> 
			</a>
		</div>
	</div>

	<div class="post_right">
		<div class="post_url">  <a target="_blank" class="post_title" onclick="<?php echo $link_url; ?>"> <?php echo $link_title; ?> </a> 	</div>
		<div class="post_desc"> <?php echo $link_desc; ?> 	</div>
		
		<div class="post_footer"> By 
		  	<a class="small_link" onclick="javascript:friendProfile(<?php echo $uid;?>)"> 
					<?php echo $name; ?>
			</a> in 
			<a class="small_link" onclick="javascript:group(<?php echo $uid.','.$groupid; ?>,'<?php echo $group_name; ?>',0,4)"><?php echo $group_name_new; ?></a>
		</div>
	</div>
</div>

Similar Tags: 
<br/>
<?php 

$query = "select tag from tags where uid=$uid and tagid in (select tagid from taglink where linkid=$linkid and uid=$uid) limit 0,10";
$result= mysql_query($query);	
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "<br/>";
   echo $message;
}

while($row = mysql_fetch_array($result))
{
	$t2=html_entity_decode($row[0],ENT_QUOTES,'UTF-8');
	$t2=addslashes($t2);
	echo '<a class="tag" onclick="javascript:singleTag(\''.t2.'\',0,4)" >'.$row[0].'</a>';
}

?>

<fb:comments xid='<?php echo "linkstar-$uid-$linkid"; ?>' width='550' publish_feed='false' numposts='3' showform='false' simple='true' reverse='false' > 
</fb:comments>
<?php

mysql_close($con);

?>
